#include <cstdio>
#include <queue>
#include <vector>
using namespace std;


#define MAXN 20000+5

int N;
priority_queue<long long, vector<long long>, greater<long long> > q;

int main()
{
    scanf("%d", &N);
    for (int i=0; i<N; i++) {
        long long L;
        scanf("%lld", &L);
        q.push(L);
    }
    long long sum = 0;
    while (!q.empty()) {
        long long a=0, b=0;
        a=q.top(); q.pop();
        if (!q.empty()) {
            b=q.top(); q.pop();
        }
        sum += a+b;
        if (!q.empty()) {
            q.push(a+b);
        }
    }
    printf("%lld\n", sum);
    return 0;
}
